/* config */
import * as config from '@src/component/form/config';
/* component */
import MobileShowSetting from '@src/component/form/common/setting/MobileShowSetting.vue';
import FormTitleSetting from '@src/component/form/common/setting/FormTitleSetting.vue';
import FormDescribeSetting from '@src/component/form/common/setting/FormDescribeSetting.vue';
import FormRequiredSetting from '@src/component/form/common/setting/FormRequiredSetting.vue';
import FormSearchSetting from '@src/component/form/common/setting/FormSearchSetting.vue';
import FormRepeatSetting from '@src/component/form/common/setting/FormRepeatSetting.vue';
import FormVisibleSetting from '@src/component/form/common/setting/FormVisibleSetting.vue';
import FormDisplaymodeSetting from '@src/component/form/common/setting/FormDisplaymodeSetting.vue';
import FormDefaultValueSetting from '@src/component/form/common/setting/FormDefaultValueSetting.vue';
import FormPublicSetting from '@src/component/form/common/setting/FormPublicSetting.vue';
import FormVisibleCustomerSetting from '@src/component/form/common/setting/FormVisibleCustomerSetting.vue';
import ApproveSetting from '@src/component/form/common/setting/ApproveSetting.vue';
import FieldMapSetting from '@src/component/form/common/setting/FieldMapSetting.vue';
import FormHelpTips from '@src/component/form/common/setting/FormHelpTips.vue';
import FormDefaultCurrencySetting from '@src/component/form/common/setting/FormDefaultCurrencySetting.vue';
import FormCheckCurrencySetting from '@src/component/form/common/setting/FormCheckCurrencySetting.vue';
import FormLimitWordSetting from '@src/component/form/common/setting/FormLimitWordSetting.vue';
import FormDateFormatSetting from '@src/component/form/common/setting/FormDateFormatSetting.vue'
/* enum */
import TableNameEnum from '@model/enum/TableNameEnum.ts';
import { isFalsy } from 'pub-bbx-utils'

import { getRootWindow } from '@src/util/dom'
import useFormMultiLanguage from '@hooks/useFormMultiLanguage'
const { internationalGray } = useFormMultiLanguage()

const defaultLanguages = [
	{
		language: 'zh',
		description: '简体中文',
		remark: '简体中文',
	},
	{
		language: 'en',
		description: 'English(US)',
		remark: '英语',
	},
	{
		language: 'ja',
		description: '日本語',
		remark: '日语',
	},
	{
		language: 'ko',
		description: 'Korean (KO)',
		remark: '韩语',
	},
];

const SettingMixin = {
  computed: {
    // 是否显示可见性(事件和工单都需要显示客户可见性)
    isShowVisibleCustomer() {
      return this.isEventMode || this.isTaskModeForVisibleCustomer;
    },
    // 工单显示客户可见性（有的控件只有工单需要显示）
    isTaskModeForVisibleCustomer() {
      return this.mode === 'task' && !this.field.isCommon;
    },
    // 是否是事件设置模式
    isEventMode() {
      return this.mode === 'event' || this.mode === 'eventReceipt';
    },
    isOnlyEventMode() {
      return this.mode === 'event';
    },
    isOnlyTaskMode() {
      return this.mode === 'task';
    },
    // 是否是 工单模式
    isTaskMode() {
      return this.mode === 'task' || this.mode === 'customer_card';
    },
    // 是否是 产品模式
    isOnlyProductMode() {
      return this.mode === 'product';
    },
    // 是否是附加组件表单
    isTaskCardForm() {
      return [TableNameEnum.TaskCard, TableNameEnum.CustomerCard, TableNameEnum.ProductCard, TableNameEnum.ProductRegister, TableNameEnum.EventCard ].indexOf(this.mode) > -1
    },
    // 工单：移动端显示的 字段列表
    mobileShowField() {
      return this.fields.filter(field => field.isAppShow === 1);
    },
    // 名字最大长度
    nameMaxLength(){
      return config.FIELD_NAME_LENGTH_MAX;
    },
    // 占位符最大长度
    placeholderMaxLength(){
      return config.FIELD_PLACEHOLER_LENGTH_MAX;
    },
    // 工单移动端展示最大数量
    taskMobileShowMaxLengthMax() {
      return config.TASK_MOBILE_SHOW_MAX_LENGTH_MAX;
    },
    /** 
    * @description 允许设为公用字段
    * 1.工单表单或回执表单
    * 2.且不是公共字段
    */
    allowPublicSet() {
      let modeArr = [TableNameEnum.Task, TableNameEnum.TaskReceipt];
      return modeArr.indexOf(this.mode) > -1 && !this.field.isCommon;
    },
    // 只有事件的物流组件展示客户查询
    allowCustomLook() {
      return this.mode === 'event' || this.mode === 'eventReceipt'
    },
    // 获取语言列表
    getLanguage() {
      const RootWindow = getRootWindow(window);
      return RootWindow.languages || defaultLanguages;
    },
    // 是否是服务商表单或工程师表单
    isServiceProviderFlag() {
      return this.mode === 'service_provider' || this.mode === 'service_engineer'
    },
    // 是否是工程师表单
    isOnlyEngineerFlag() {
      return this.mode === 'service_engineer'
    },
    // 亚马芬灰度
    AMER_PRINT_AUTH() {
      const RootWindow = getRootWindow(window);
      return RootWindow?.grayAuth?.AMER_PRINT ?? false;
    },
    internationalGray() {
      return internationalGray;
    },
    isNotSupportDateTimeSettingTypeMode() {
      return ["projectType", "projectTask"].includes(this.mode);
    },
    isShowPlanStartTimeSettingType() {
      return isFalsy(this.isNotSupportDateTimeSettingTypeMode)
    },
    isShowPlanEndTimeSettingType() {
      return isFalsy(this.isNotSupportDateTimeSettingTypeMode)
    }
  },
  components: {
    [MobileShowSetting.name]: MobileShowSetting,
    [FormTitleSetting.name]: FormTitleSetting,
    [FormDescribeSetting.name]: FormDescribeSetting,
    [FormRequiredSetting.name]: FormRequiredSetting,
    [FormSearchSetting.name]: FormSearchSetting,
    [FormRepeatSetting.name]: FormRepeatSetting,
    [FormVisibleSetting.name]: FormVisibleSetting,
    [FormDisplaymodeSetting.name]: FormDisplaymodeSetting,
    [FormDefaultValueSetting.name]: FormDefaultValueSetting,
    [FormPublicSetting.name]: FormPublicSetting,
    [FormVisibleCustomerSetting.name]: FormVisibleCustomerSetting,
    [ApproveSetting.name]: ApproveSetting,
    [FieldMapSetting.name]: FieldMapSetting,
    [FormHelpTips.name]: FormHelpTips,
    [FormDefaultCurrencySetting.name]: FormDefaultCurrencySetting,
    [FormCheckCurrencySetting.name]: FormCheckCurrencySetting,
    [FormLimitWordSetting.name]: FormLimitWordSetting,
    [FormDateFormatSetting.name]: FormDateFormatSetting
  }
}

export default SettingMixin;